int x = 0; 
int x1 = 20;
int x2 = 60;
int x3 = 80;
boolean direction = true; 
int rectWidth = 50; 


void setup() {
  size(500, 300);   
  background(255);  
}

void draw() {
  if(direction){
    if(x<width-rectWidth)
    {
      x++;
      x1++;
      x2++;
      x3++;
    }else{
      direction = false;
    }
  }else{
    if(x>0){
      x--;
      x1--;
      x2--;
      x3--;
    }else{
       direction = true;
    }
  }
  background(100);
  fill(0,20,178);
  rect(x,100,100,rectWidth);
  fill(400,104,0);
  triangle(x1,100,x2, 55, x3, 100);
}




